﻿app.controller("detailsController", function ($scope, $http, $location, $routeParams, Cart) {
    $scope.cart = Cart;
    $scope.getOneGadget = function (id) {
        console.log("Get one gadget: " + id);
        $http({ method: "GET", url: "/api/ApiGadget/" + id })
            .success(function (gadgetVm) {
                $scope.GadgetVM = gadgetVm;
            })
    };
    //I don't think we need this method
    //$scope.editGadget = function (id) {
    //    console.log("Edit a Gadget :" + id);
    //    $http({ method: "GET", ur: "/api/ApiGadget/" + id })
    //        .success(function (gadgetVm) {
    //            $scope.Gadget = gadgetVm.gadget;
    //        })
    //};
    $scope.updateGadget = function () {
        console.log("Update gadget running");
        $http({ method: "PUT", url: "api/ApiGadget/" + $routeParams.id, data: $scope.GadgetVM.Gadget })
            .success(function (gadgetId) {
                $location.path("/admin_product_details/" + gadgetId);
            })
    };
    $scope.AddPicture = function () {
        console.log("Add picture firing");
        $http({ method: "POST", url: "/api/ApiPicture", data: $scope.GadgetVM }).success(function (gadgetId) {
            $scope.getOneGadget(gadgetId);
        })
    };
    $scope.deletePicture = function (id) {
        console.log("Delete picture firing :" + id);
        $http({ method: "DELETE", url: "/api/ApiPicture/" + id }).success(function (gadgetId) {
            $scope.getOneGadget(gadgetId);
        })
    };
    $scope.addItem = function (id) {
        $http({ method: "GET", url: "api/ApiGadget/" + id })
            .success(function (gadgetVM) {
                $scope.cart.push(gadgetVM.Gadget);
                console.log($scope.cart);
            })
    };
    $scope.getOneGadget($routeParams.id);
    //$scope.editGadget($routeParams.id);
})